package com.imooc.Thread.TicketsDemo;

/**
 * Created by Administrator on 2017/7/17.
 */
class MyRunnable implements Runnable{

    private Integer ticketsCount = 5;   //五张票
//    private String name;    //窗口、线程的名字
//
//    public MyRunnable(String name) {
//        this.name = name;
//    }

    @Override
    public void run() {
        while(ticketsCount > 0) {
            System.out.println(Thread.currentThread().getName() + "买了一张票，剩余票数为：" + --ticketsCount);
        }
    }

}
public class TicketsRunnable {
    public static void main(String[] args) {
        MyRunnable mr = new MyRunnable();

        Thread mt1 = new Thread(mr, "窗口1");
        Thread mt2 = new Thread(mr, "窗口2");
        Thread mt3 = new Thread(mr, "窗口3");

        mt1.start();
        mt2.start();
        mt3.start();
    }
}
